package com.springcloud.dto;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.springcloud.utils.ConstantUtil;
import lombok.Data;

import java.util.List;

@Data
public class WebResultDto {
    private String status;
    private String info;
    private JSONArray data;

    public WebResultDto() {
        status = ConstantUtil.ExeState.EXE_FAIL;
        info = ConstantUtil.ExeStateString.STRING_FAIL;
        data = new JSONArray();
    }

    public <T> void success(List<T> list) {
        status = ConstantUtil.ExeState.EXE_SUCCESS;
        info = ConstantUtil.ExeStateString.STRING_SUCCESS;
        if (list != null && list.size() > 0) {
            data.clear();
            for (T t : list) data.add(t);
        }
    }
    public <T> void success() {
        status = ConstantUtil.ExeState.EXE_SUCCESS;
        info = ConstantUtil.ExeStateString.STRING_SUCCESS;

    }
    public <T> void success(String s, JSONObject list) {
        status = ConstantUtil.ExeState.EXE_SUCCESS;
        info = ConstantUtil.ExeStateString.STRING_SUCCESS;
        if (list != null && list.size() > 0) {
            data.clear();
            data.add(list);
        }
    }

//	public String wrapper(Object obj) {
//		if (obj != null) {
//			JSONObject jsonObj = new JSONObject();
//			jsonObj.put("data", obj);
//			return jsonObj.toJSONString();
//		}
//		return null;
//	}


}
